package api

import (
	"day14/video-share/api-getaway/basic/config"
	"day14/video-share/api-getaway/basic/handler/request"
	__ "day14/video-share/api-getaway/basic/proto"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func CreateVideo(c *gin.Context) {

	var video request.CreateVideo
	err := c.ShouldBind(&video)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "参数错误",
		})
		return
	}
	r, err := config.VideoClient.CreateVideo(c, &__.CreateVideoReq{
		Title:    video.Title,
		Content:  video.Content,
		ImageUrl: video.ImageUrl,
		VideoUrl: video.VideoUrl,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
	})

}
